package com.itheima.stringtest;

import java.util.Scanner;

public class Test6 {
    public static void main(String[] args) {
        //把2135变成：零佰零拾零万贰仟壹佰叁拾伍元
        //分析1.将2135变成贰壹叁伍 2.贰壹叁伍变成零零零贰壹叁伍
        //3.添加单位变成零佰零拾零万贰仟壹佰叁拾伍元
        //1.键盘录入一个金额
        int money = 0;
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入一个金额");
            money = sc.nextInt();
            if (money > 0 && money <= 9999999) {
                break;
            } else {
                System.out.println("输入的金额不在合法范围内，请重新输入");
            }
        }
        //System.out.println(money);
        //2.将阿拉伯数字变成中文数字
        String str = "";
        while (money != 0) {
            int ge = money % 10;
            money = money / 10;
            char capitalNumber = getCapitalNumber(ge);
            str = capitalNumber + str;
        }
        //System.out.println(str);
        //3.给中文数字前面补零
        int count = 7 - str.length();
        for (int i = 0; i < count; i++) {
            str = '零' + str;
        }
        //System.out.println(str);
        //4.将单位插入到中文数字中
        char[] arr0 = {'佰', '拾', '万', '仟', '佰', '拾', '元'};
        String result = "";
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            result = result + c + arr0[i];
        }
        System.out.println(result);
    }

    public static char getCapitalNumber(int num) {
        char[] arr = {'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'};
        return arr[num];
    }
}
